package com.xhui.vimarket.zkplus.zul.attr.evt;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;

import com.xhui.vimarket.zkplus.callback.EvtCallback;
import com.xhui.vimarket.zkplus.zul.attr.ada.AttrButtonTextBtnIntf;
import com.xhui.vimarket.zkplus.zul.attr.bean.ButtonTextDataVo;
import com.xhui.vimarket.zkplus.zul.attr.evt.rtime.AttrRtimeBaseComposer;

/**
 * @版权：福富软件 版权所有 (c) 2010.
 * @文件：com.xhui.vimarket.zkplus.zul.attr.evt.AttrButtonTextBtnComposer.java
 * @所含类：
 * @author: wuyx
 * @version: V1.0
 * @see:
 * @创建日期：2010-12-20
 * @功能说明：客服中心
 * @修改记录： =============================================================<br>
 *        日期:2010-12-20 创建
 *        =============================================================<br>
 */
public class AttrButtonTextBtnComposer extends AttrRtimeBaseComposer
    implements AttrButtonTextBtnIntf, EvtCallback {

	@Override
	public void callback(Object object) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void initVal() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void beforeValidateExec() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onInitVal(Event event) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void doFillReturnData(ButtonTextDataVo btdv) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void doShowReturnData(ButtonTextDataVo btdv) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Component getRootComp() {
		// TODO Auto-generated method stub
		return null;
	}/*
    *//**
     * POSITON_TOP_PX.
     *//*
    public static final String  POSITON_TOP_PX     = "24px";
    *//**
     * serialVersionUID.
     *//*
    private static final long   serialVersionUID   = 4579587521568091904L;
    *//**
     * TEST_ZUL.
     *//*
    private static final String TEST_ZUL           = "/mod_order/attrcomp/demo_btn_comp.zul";
    
    *//**
     * ATTR_CALLBACK_FN.
     *//*
    public static final String  ATTR_CALLBACK      = "attr_callback";
    *//**
     * TAG_HIDE_RESET_BTN.
     *//*
    public static final String  TAG_HIDE_RESET_BTN = "TAG_HIDE_RESET_BTN";
    
    *//**
     * 上级容器.
     *//*
    private Hbox                hbox;
    
    @Override
    public ComponentInfo doBeforeCompose(final Page page, final Component comp,
        final ComponentInfo info) {
        return info;
    }
    
    @Override
    public void doAfterCompose(final Component comp) throws Exception {
        super.doAfterCompose(comp);
        this.initParams(comp);
    }
    
    *//**
     * initParams.
     * @param comp Component
     *//*
    public void initParams(final Component comp) {
        this.hbox = (Hbox) comp.getParent().getParent();
    }
    
    *//**
     * onClick.
     *//*
    public void onClick() {
        this.onShowWind();
    }
    
    *//**
     * 显示高级查询窗口.
     *//*
    public void onShowWind() {
        final Map<String, Object> args = EvtCallbackImpl.newArg(
            AttrButtonTextBtnComposer.ATTR_CALLBACK, this);
        args.put(EvtCallbackImpl.CALLFROM, this.self.getUuid());
        // open window
        Window win = this.getPreWind();
        if (win == null) {
            win = (Window) Executions.createComponents(AttrButtonTextBtnComposer.TEST_ZUL, null,
                args);
        }
        this.openWind(win, ZkWindUtil.WIN_MAX_SIZE);
    }
    
    *//**
     * createComponents.
     * 
     * @param parentComp Component
     * @param zulUrl String
     * @param args Map<String, Object>
     * @param strParams String
     * @return Component
     * @author wuyx
     * 2011-5-5 wuyx 
     *//*
    public Component createComponents(String zulUrl, final Component parentComp,
        Map<String, Object> args, final String strParams) {
        if (StrUtil.isNullOrEmpty(strParams)) {
            return ZkWindUtil.createComponentsWithUrlParams(parentComp, zulUrl, args);
        }
        if ((strParams + "").indexOf("?") > -1) {
            return ZkWindUtil.createComponentsWithUrlParams(parentComp, zulUrl + strParams, args);
        }
        return ZkWindUtil.createComponentsWithUrlParams(parentComp, zulUrl + "?" + strParams, args);
    }
    
    *//**
     * doFillReturnData.
     * 
     * @param btdv ButtonTextDataVo
     *//*
    public void doFillReturnData(final ButtonTextDataVo btdv) {
        final Textbox textbox = this.getTextbox();
        if (btdv.isReset()) { // 清空
            textbox.setValue("");
            textbox.removeAttribute(AttrButtonTextComp.TAG_VALUE_ID);
            textbox.removeAttribute(AttrButtonTextComp.TAG_VALUE_OBJECT);
        } else { // 设置
            textbox.setValue(btdv.getValueLabel() == null ? btdv.getValueName()
                : btdv.getValueLabel());
            textbox.setAttribute(AttrButtonTextComp.TAG_VALUE_ID, btdv.getValueId());
            textbox.setAttribute(AttrButtonTextComp.TAG_VALUE_OBJECT, btdv.getData());
        }
    }
    
    *//**
     * doFillReturnData.
     * 
     * @param btdv ButtonTextDataVo
     *//*
    public void doShowReturnData(final ButtonTextDataVo btdv) {
        final Textbox textbox = this.getTextbox();
        if (btdv.isReset()) { // 清空
            textbox.setValue("");
            textbox.removeAttribute(AttrButtonTextComp.TAG_VALUE_ID);
            textbox.removeAttribute(AttrButtonTextComp.TAG_VALUE_OBJECT);
        } else { // 设置
            textbox.setValue(btdv.getValueLabel() == null ? btdv.getValueName()
                : btdv.getValueLabel());
            textbox.setAttribute(AttrButtonTextComp.TAG_VALUE_ID, btdv.getValueId());
            textbox.setAttribute(AttrButtonTextComp.TAG_VALUE_OBJECT, btdv.getData());
        }
    }
    
    @Override
    public void callback(final Object object) {
        if (object != null && (object instanceof ButtonTextDataVo)) { // 回调数据不为空，并且正确
            final ButtonTextDataVo btdv = (ButtonTextDataVo) object;
            this.doFillReturnData(btdv);
        }
    }
    
    public Hbox getHbox() {
        return this.hbox;
    }
    
    *//**
     * getTextbox.
     * 
     * @return Textbox
     * @author wuyx
     * 2011-1-25 wuyx 
     *//*
    public Textbox getTextbox() {
        return AttrButtonTextComp.getTextbox(this.getHbox());
    }
    
    *//**
     * 
     * 方法功能:
     *  获取自动选号按钮.
     * @return Button
     * @author: linzhiqiang
     * @修改记录： 
     * ==============================================================<br>
     * 日期:2011-12-13 linzhiqiang 创建方法，并实现其功能
     * ==============================================================<br>
     *//*
    public Button getAutoNbrBtn() {
        return AttrButtonTextComp.getAutoNbrBtn(this.getHbox());
    }
    
    *//**
     * 
     * 方法功能:
     *  获取自助（预约）选号占用按钮.
     * @param root
     * @return Button
     * @author: chenmh
     * @修改记录： 
     * ==============================================================<br>
     * 日期:2011-12-27 chenmh 创建方法，并实现其功能
     * ==============================================================<br>
     *//*
    public Button getOccupyBtn() {
        return AttrButtonTextComp.getOccupyBtn(this.getHbox());
    }

    public Button getWriteCardBtn() {
        return AttrButtonTextComp.getWriteCardBtn(this.getHbox());
    }
    *//**
     * getMainButton.
     * 
     * @return Button
     * @author wuyx
     * 2011-1-25 wuyx 
     *//*
    public Button getMainButton() {
        return AttrButtonTextComp.getButton(this.getHbox());
    }
    
    *//**
     * getImgButton.
     * 
     * @return Button
     * @author wuyx
     * 2011-1-25 wuyx 
     *//*
    public Button getImgButton() {
        return AttrButtonTextComp.getImgbtn(this.getHbox());
    }
    
    public void setHbox(final Hbox hbox) {
        this.hbox = hbox;
    }
    
    *//**
     * getBtnType.
     * 
     * @return String
     * @author wuyx
     * 2011-1-25 wuyx 
     *//*
    public String getBtnType() {
        if (this.self.hasAttribute(AttrButtonTextComp.STYLE_TEXTIMG)) {
            return AttrButtonTextComp.STYLE_TEXTIMG;
        } else {
            return AttrButtonTextComp.STYLE_BTNTEXT;
        }
    }
    
    *//**
     * openWind.
     * 
     * @param win Window
     * @param size int
     * @author wuyx
     * 2011-1-25 wuyx 
     *//*
    public void openWind(final Window win, final int size) {
        this.openWind(win, size, null, null, null);
    }
    
    *//**
     * openWind.
     * 
     * @param win Window
     * @param sw String
     * @param sh String
     * @author wuyx
     * 2011-4-18 wuyx 
     *//*
    public void openWind(final Window win, final String sw, final String sh) {
        this.openWind(win, -1, sw, sh, null);
    }
    
    *//**
     * openWind.
     * 
     * @param win Window
     * @param size int
     * @param title String
     * @author wuyx
     * 2011-1-25 wuyx 
     *//*
    public void openWind(final Window win, final int size, final String title) {
        this.openWind(win, size, null, null, title);
    }
    
    *//**
     * openWind.
     * 
     * @param win Window
     * @param sw String
     * @param sh String
     * @param title String
     * @author wuyx
     * 2011-4-18 wuyx 
     *//*
    public void openWind(final Window win, final String sw, final String sh, final String title) {
        this.openWind(win, -1, sw, sh, title);
    }
    
    *//**
     * openWind.
     * 
     * @param win Window
     * @param size int
     * @param sw String
     * @param sh String
     * @param title String
     * @author wuyx
     * 2011-1-25 wuyx 
     *//*
    private void openWind(final Window win, final int size, final String sw, final String sh,
        final String title) {
        // 标题处理
        if (title != null) {
            win.setTitle(title);
        }
        win.setBorder("normal");
        if (AttrButtonTextComp.STYLE_TEXTIMG.equals(this.getBtnType())) {
            final String dstyle = this.getHbox().getAttribute(AttrBaseComp.COMP_STYLE) + "";
            if (dstyle.equals(AttrButtonTextComp.STYLE_TEXTIMG)) {
                // win.setParent(this.self.getNextSibling());
                win.setParent(AttrButtonTextComp.getPopParent(this.getHbox()));
                win.setPosition("parent");
                win.setTop(POSITON_TOP_PX);
                if (sw == null && sh == null) {
                    ZkWindUtil.doOverlapped(win, size);
                } else {
                    ZkWindUtil.doOverlapped(win, sw, sh);
                }
                if (title != null && "".equals(title)) {
                    win.setBorder("none");
                }
            } else if (dstyle.equals(AttrButtonTextComp.STYLE_TEXTIMG_CEN)) {
                win.setParent(AttrButtonTextComp.getPopParent(this.getHbox()));
                win.setPosition("center");
                win.setTop(POSITON_TOP_PX);
                if (sw == null && sh == null) {
                    ZkWindUtil.doOverlapped(win, size);
                } else {
                    ZkWindUtil.doOverlapped(win, sw, sh);
                }
                if (title != null && "".equals(title)) {
                    win.setBorder("none");
                }
            } else if (dstyle.equals(AttrButtonTextComp.STYLE_TEXTPOP_CEN)) {
                win.setParent(AttrButtonTextComp.getPopParent(this.getHbox()));
                win.setPosition("center");
                win.setTop(POSITON_TOP_PX);
                if (sw == null && sh == null) {
                    ZkWindUtil.doPopup(win, size);
                } else {
                    ZkWindUtil.doPopup(win, sw, sh);
                }
                if (title != null && "".equals(title)) {
                    win.setBorder("none");
                }
                win.setClosable(false);
            } else {
                // win.setParent(this.self.getNextSibling());
                win.setParent(AttrButtonTextComp.getPopParent(this.getHbox()));
                win.setPosition("parent");
                win.setTop(POSITON_TOP_PX);
                if (sw == null && sh == null) {
                    ZkWindUtil.doPopup(win, size);
                } else {
                    ZkWindUtil.doPopup(win, sw, sh);
                }
                if (title != null && "".equals(title)) {
                    win.setBorder("none");
                }
                win.setClosable(false);
            }
        } else {
            if (sw == null && sh == null) {
                ZkWindUtil.doModal(win, size);
            } else {
                ZkWindUtil.doModal(win, sw, sh);
            }
        }
    }
    
    *//**
     * getPreWind.
     * 
     * @return Window
     * @author wuyx
     * 2011-1-25 wuyx 
     *//*
    @SuppressWarnings("unchecked")
    public Window getPreWind() {
        final Span span = (Span) AttrButtonTextComp.getPopParent(this.getHbox());
        if (span != null) {
            final List<Component> list = span.getChildren();
            if (list != null && list.size() > 0) {
                return (Window) span.getLastChild();
            }
        }
        return null;
    }
    
    @Override
    public void beforeValidateExec() {
    }
    
    @Override
    public Component getRootComp() {
        return this.getHbox();
    }
    
    @Override
    public void onInitVal(Event event) {
        this.initVal();
    }
    
    *//**
     * resetMustRule.
     * 
     * @param ruleFlag boolean
     * @author wuyx
     * 2011-1-25 wuyx 
     *//*
    public void resetMustRule(boolean ruleFlag) {
        AttrCompUtil.resetMustRule(this.getHbox(), ruleFlag);
    }
    
    *//**
     * 定义自动触发的事件.
     * 
     * @param event Event
     * @author wuyx
     * 2011-11-22 wuyx 
     *//*
    public void onAutoClick(Event event) {
        Events.sendEvent(Events.ON_CLICK, this.self, null);
    }
    
    *//**
     * 获取参数2"?"后面的参数配置信息.
     * @return 参数Map
     * @author g.luxb
     *         2011-12-16 g.luxb
     *//*
    public Map<String, String> getParam2Args() {
        Map<String, String> result = new HashMap<String, String>();
        String url = StrUtil.strnull(hbox.getAttribute(AttrBaseComp.COMP_ARG));
        if (url != "") {
            String[] urlSplit = url.split("&");
            for (int i = 0; i < urlSplit.length; i++) {
                result.put(urlSplit[i].split("=")[0], urlSplit[i].split("=")[1]);
            }
        }
        return result;
    }
    
    public void checkProperty(String rs) {
        if (!StrUtil.isNullOrEmpty(rs)) {
            // 设置错误，规则验证不通过,还原
            this.getTextbox().setValue("");
            // 展示提示信息
            ErrorBox.newInstance()
                .showError(
                    AttrCompFactory.getInstByComponent(this.getTextbox()).getMsgComp(
                        this.getTextbox()), rs);
        }
    }
    
    *//**
     * 获取已拆号码按钮.
     * @return 按钮
     * @author luxb
     *         2012-2-9 luxb
     *//*
    public Button getOldNbrBtn() {
        return AttrButtonTextComp.getOldNbrBtn(this.getHbox());
    }
    *//**
     * 
     * 获取号码迁移按钮.
     * @return 按钮
     * @author luxb
     * 		   2012-4-26 luxb
     *//*
    public Button getMoveAccNbrBtn() {
        return AttrButtonTextComp.getMoveAccNbrBtn(this.getHbox());
    }
    
    *//**
     * 发展员工清空按钮
     * .
     * 
     * @return
     * @author zhenggw
     * 2012-8-13 zhenggw
     *//*
    public Button getClearBtn() {
        return AttrButtonTextComp.getClearBtn(this.getHbox());
    }
*/}
